<?php
namespace App\Services;

use Illuminate\Support\Facades\Http;

class MakeCoinInfoService
{
    private static function handleRequest($method, $path, array $data = []) : array
    {
        $url = config('services.go.url').$path;

        $client = Http::timeout(9) -> accept('application/json');

        if($method == "GET") {
            $response = $client -> get($url, $data);
        } else {
            $response = $client -> post($url, $data);
        }

        return $response->json();
    }

    public static function generateMnemonic(int $account_id) : array
    {
        $path = "/api/v1/user/generate/mnemonic";

        $data = [
            "accountId" => $account_id
        ];

        $res = self::handleRequest("GET", $path, $data);

        return $res;
    }

    public static function generateAddress(int $account_id) : array
    {
        $path = "/api/v1/user/generate/address";

        $data = [
            "accountId" => $account_id
        ];

        $res = self::handleRequest("GET", $path, $data);

        return $res;
    }
}
